
#ifndef _SPINLOCK_H_
#define _SPINLOCK_H_

#include <atomic>

class spin_mutex {
	std::atomic_flag flag;
public:
	spin_mutex(){ flag.clear();}
	void lock() {
		while(flag.test_and_set(std::memory_order_acquire))
			;
	}
	void unlock() {
		flag.clear(std::memory_order_release);
	}
private:
	spin_mutex(const spin_mutex&);
	spin_mutex& operator= (const spin_mutex&);
};

#endif